package dao;

import java.lang.reflect.Array;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import model.roleModel;
import model.userModel;

import util.dataUtil;

public class menuDao {
	public static ArrayList<roleModel> getAllRoleMenuByID(int id) {
		ArrayList<roleModel> role=new ArrayList<roleModel>();
		String sql = "SELECT * FROM Role_Menu WHERE IdRole= '" + id +"'";
		try {
			PreparedStatement ps = dataUtil.getconnConnection().prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				roleModel model = new roleModel();
				model.setIdMenu(rs.getString("IdMenu"));
				role.add(model);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return role;
	}
	///////////////
	public static ArrayList<userModel> getID(String user) {
		String sql = "SELECT * FROM Sys_user WHERE username=?";
		
		ArrayList<userModel> modelid = new ArrayList<userModel>();
		try {
			PreparedStatement ps = dataUtil.getconnConnection().prepareStatement(sql);
			ps.setString(1, user);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				userModel model = new userModel();
				model.setIdrole(rs.getInt("idrole"));
				modelid.add(model);
			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		
		return modelid;
	}
	public static int getIDuser(String user) {
		String sql = "SELECT * FROM Sys_user WHERE username=?";
		int a=-1;
		//ArrayList<userModel> modelid = new ArrayList<userModel>();
		try {
			PreparedStatement ps = dataUtil.getconnConnection().prepareStatement(sql);
			ps.setString(1, user);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				a=rs.getInt("id");

			}
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}
		
		return a;
	}
}
